package com.zzyl.controller;

import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.service.NursingLeveService;
import com.zzyl.vo.NursingLevelV0;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursingLevel")
@Api(tags = "护理等级模块")
public class NursingLeveController {

    @Autowired
    private NursingLeveService nursingLeveService;


    @GetMapping("/level")
    @ApiOperation("查询所有等级")
    public ResponseResult getAllLevcl(){
        List<NursingLevelV0> list = nursingLeveService.getAllLevel();
        return ResponseResult.success(list);
    }

    @PostMapping("/insert")
    @ApiOperation(value = "新增护理等级")
    public ResponseResult addLevel(@RequestBody NursingLevelDto dto){
        nursingLeveService.addLevel(dto);
        return ResponseResult.success();
    }

    @GetMapping("/listByPage")
    @ApiOperation(value = "条件分页查询")
    public ResponseResult getByPage(@RequestParam(defaultValue = "1") Integer pageNum,
                                    @RequestParam(defaultValue = "10") Integer pageSize,
                                    String name,
                                    Integer status){
        return nursingLeveService.getByPage(pageNum,pageSize,name,status);
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询")
    public ResponseResult getById(@PathVariable Integer id){
        NursingLevelV0 nursingLevelV0 = nursingLeveService.getById(id);
        return ResponseResult.success(nursingLevelV0);
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改护理等级")
    public ResponseResult update(@RequestBody NursingLevelDto dto){
        nursingLeveService.update(dto);
        return ResponseResult.success();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "根据id删除护理等级数据")
    public ResponseResult delete(@PathVariable Integer id){
        nursingLeveService.dalete(id);
        return ResponseResult.success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "修改护理等级状态")
    public ResponseResult updateStatus(@PathVariable Integer id,@PathVariable Integer status){
        nursingLeveService.updateStatus(id,status);
        return ResponseResult.success();
    }

    public void demo(){
        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {

            }
        },"1");
    }
}
